package net.chrisrichardson.ec2deployer.applications

import net.chrisrichardson.ec2deployer.core.Application
import net.chrisrichardson.ec2deployer.core.EC2Server

class TerracottaServer extends Application {

    def static TC_INSTALL_ROOT = "/var/lib/terracotta-2.5.4"
    int serverId

    TerracottaServer(EC2Server ec2Server, int serverId) {
        super(ec2Server)
        this.serverId = serverId
    }

    void startTerracotta() {
        // TODO JAVA_HOME
        exec "(export JAVA_HOME=/usr/java/default ; nohup ${TC_INSTALL_ROOT}/bin/start-tc-server.sh -n Server${serverId} ) < /dev/null > /dev/null 2>&1 &"
    }

    void stopTerracotta() {
        // TODO JAVA_HOME
        exec "export JAVA_HOME=/usr/java/default ; ${TC_INSTALL_ROOT}/bin/stop-tc-server.sh -n Server${serverId}"
    }
}